/**
 * 查找树结构中的某项数据
 * @param tree 源数据数组
 * @param targetValue 目标value
 * @param targetKey 目标key，默认'id'
 * @param childrenKey 递归下一层的key，默认'children'
 * @returns 返回遍历到的目标对象 | undefined
 */
export function findTerrTarget<T = any>(
	tree: T[],
	targetValue: string | number,
	targetKey = 'id',
	childrenKey = 'children'
): T | undefined {
	if (!tree) return;

	for (const item of tree) {
		if ((item as any)[targetKey] === targetValue) {
			return item;
		} else {
			const childResult = findTerrTarget(
				(item as any)[childrenKey],
				targetValue,
				targetKey,
				childrenKey
			);
			if (childResult) {
				return childResult;
			}
		}
	}
}
